package frame.options.simulation.create.coordinated;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.border.EmptyBorder;

@SuppressWarnings("serial")
public class CoordinatedPanel extends JPanel
{
	private JRadioButton yesRadioButton;
	public JRadioButton getYesRadioButton(){ return yesRadioButton; }
	public void setYesRadioButton( JRadioButton yesRadioButton ){ this.yesRadioButton = yesRadioButton; }
	
    private JRadioButton noRadioButton;
    public JRadioButton getNoRadioButton(){ return noRadioButton; }
	public void setNoRadioButton( JRadioButton noRadioButton ){ this.noRadioButton = noRadioButton; }
	
	private JLabel errorLabel;
	public JLabel getErrorLabel(){ return errorLabel; }
	public void setErrorLabel( JLabel errorLabel ){ this.errorLabel = errorLabel; }
	
    public CoordinatedPanel()
    {
        this.setNoRadioButton( new JRadioButton( "No" ) );
        this.getNoRadioButton().setSelected( true );
        
    	this.setYesRadioButton( new JRadioButton( "Yes" ) );
        this.getYesRadioButton().setSelected( false );
        
		ButtonGroup buttonGroup = new ButtonGroup();
		buttonGroup.add( this.getNoRadioButton() );
        buttonGroup.add( this.getYesRadioButton() );
        
        this.setLayout( new BorderLayout() );
        this.add( this.titlePanel(), BorderLayout.NORTH );
        this.add( this.contentPanel(), BorderLayout.CENTER );
        this.add( this.errorPanel(), BorderLayout.SOUTH );
    }
    
    private JPanel titlePanel()
    {
    	JLabel titleLabel = new JLabel( "With coordinated virtual node and link mapping" );
        titleLabel.setFont( new Font( "MS Sans Serif", Font.BOLD, 14 ) );
        titleLabel.setBorder( new EmptyBorder( new Insets( 10, 10, 10, 10 ) ) );
        titleLabel.setOpaque( true );
        
        JSeparator separator = new JSeparator();
        
        JPanel titlePanel = new JPanel();
        titlePanel.setLayout( new java.awt.BorderLayout() );
        titlePanel.setBackground( Color.gray );
        titlePanel.add( titleLabel, BorderLayout.CENTER );
        titlePanel.add( separator, BorderLayout.SOUTH );
        
        return titlePanel;
    }
    
    private JPanel contentPanel()
	{
        JPanel contentPanel = new JPanel();
        contentPanel.setBorder( new EmptyBorder( new Insets( 50, 50, 50, 50 ) ) );
        contentPanel.add( this.selectPanel() );
        
        return contentPanel;
	}
    
    private JPanel selectPanel()
	{
        JPanel selectPanel = new JPanel();
        selectPanel.setLayout( new java.awt.GridLayout( 0, 1 ) );
        selectPanel.add( this.getNoRadioButton() );
        selectPanel.add( new JLabel() );
        selectPanel.add( this.getYesRadioButton() );
        selectPanel.add( new JLabel() );
        
        return selectPanel;
	}
    
    private JPanel errorPanel()
	{
		this.setErrorLabel( new JLabel( "" ) );
		this.getErrorLabel().setForeground( Color.RED );
		
		JPanel errorPanel = new JPanel();
		errorPanel.add( this.getErrorLabel() );
		
		return errorPanel;
	}
    
    public void addListeners( ActionListener actionListener )
    {
    	this.getYesRadioButton().addActionListener( actionListener );
    	this.getNoRadioButton().addActionListener( actionListener );
    }
    
}
